home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / mpeg / util32.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  72 lines

  1. #include <stdio.h>
  2. #include <X11/Xlib.h>
  3. #include <X11/Xutil.h>
  4. #include "video.h"
  5. #include "proto.h"
  6.  
  7. /*
  8.  * Return a pointer to a full color bit visual on the dpy
  9.  */
  10. Visual *
  11. FindFullColorVisual (dpy, depth)
  12.     Display *dpy;
  13.     int *depth;
  14. {
  15.   XVisualInfo vinfo;
  16.   XVisualInfo *vinfo_ret;
  17.   int numitems, maxdepth;
  18.   
  19.   vinfo.class = TrueColor;
  20.   
  21.   vinfo_ret = XGetVisualInfo(dpy, VisualClassMask, &vinfo, &numitems);
  22.   
  23.   if (numitems == 0) return NULL;
  24.  
  25.   maxdepth = 0;
  26.   while(numitems > 0) {
  27.     if (vinfo_ret[numitems-1].depth > maxdepth) {
  28.       maxdepth = vinfo_ret[numitems-1 ].depth;
  29.     }
  30.     numitems--;
  31.   }
  32.   XFree(vinfo_ret);
  33.  
  34.   if (maxdepth < 24) return NULL;
  35.  
  36.   if (XMatchVisualInfo(dpy, DefaultScreen(dpy), maxdepth, 
  37.                TrueColor, &vinfo)) {
  38.     *depth = maxdepth;
  39.     return vinfo.visual;
  40.   }
  41.   
  42.   return NULL;
  43. }
  44.  
  45. Window
  46. CreateFullColorWindow (dpy, x, y, w, h)
  47.     Display *dpy;
  48.     int x, y, w, h;
  49. {
  50.     int depth;
  51.     Visual *visual;
  52.     XSetWindowAttributes xswa;
  53.     unsigned int mask;
  54.     unsigned int class;
  55.     int screen;
  56.  
  57.     screen = XDefaultScreen(dpy);
  58.     class = InputOutput;    /* Could be InputOnly */
  59.     visual = FindFullColorVisual (dpy, &depth);
  60.     if (visual == NULL) {
  61.     return 0;
  62.     }
  63.     mask = CWBackPixel | CWColormap | CWBorderPixel;
  64.     xswa.colormap = XCreateColormap(dpy, XRootWindow(dpy, screen),
  65.             visual, AllocNone);
  66.     xswa.background_pixel = BlackPixel(dpy, DefaultScreen(dpy));
  67.     xswa.border_pixel = WhitePixel(dpy, DefaultScreen(dpy));
  68.  
  69.     return XCreateWindow(dpy, RootWindow(dpy, screen), x, y, w, h,
  70.     1, depth, class, visual, mask, &xswa);
  71. }
  72.